<?
	require_once('init.php');
	require_once('dataModel.php');

	$_SESSION["MenuID"]='';

	$EID=$_GET['ID'];
	$Type=$_GET['Type'];
	$pgno=$_GET['pgno'];
    
    if ($Type==0)
    {
    	$Title="新增客服人员";
		$strSQL = "select * from empInfo where 1=0";
		$imtype="0";
	}
    else if ($Type==1)
    {
    	$Title="修改客服人员";
		$strSQL = "select * from empInfo where id='".$EID."' AND shopRoomID=".$_SESSION["UID"]." ";
    }

	$db = MySQL::getInstance('','r-w'); 
	$DBR=$db->query($strSQL); 
  	$result=$db->fetch($DBR);
  	
  	if ($Type==1)
  	{
  		$imtype=$result["imType"];
	}	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=<?='utf-8';?>" />
	<title><?=$AllPageTitle;?></title>
	<link href="css/CenterMenu.css" rel="stylesheet" type="text/css" />
	
	
	<!--注意，不要改变以下三行格式 -->
	<script src="Scripts/jquery.min.js" type="text/javascript"></script>
	<script src="Scripts/jquery.ui.draggable.js" type="text/javascript"></script>
	<script src="Scripts/jquery.hiAlerts-min.js" type="text/javascript"></script>
	
	<script language="javascript">
		function goback(pgno)
		{
			self.location='empinfo.php?pgno='+pgno
		}

		function CheckData()
		{
			value = $("#empName").attr("value");
	       	if( value=="")
	       	{
				parent.hiAlert("请输入客服账号!", '系统提示');
				$("#empName").focus();
				return false;
	        }

			var temp=document.getElementsByName("imtype");
			var imtypeValue="";
			for (i=0;i<temp.length;i++)
			{
			    if(temp[i].checked)
				{
					imtypeValue=temp[i].value;
				}
			}

			var strSQL = "";                      
			strSQL+= "&empName=";
			strSQL+=$("#empName").attr("value");
			strSQL+= "&empPwd=";
			strSQL+=$("#empPwd").attr("value");
			strSQL+= "&imNumber=";
			strSQL+=$("#imNumber").attr("value");
			strSQL+= "&imType="+imtypeValue;
			strSQL+= "&Type=AddEmpName";
			
//			alert (strSQL);
			
			$.post("varifyData.php",strSQL,function(msg)
			{

//			    alert (msg);
			    
			   	if (msg=='1')
			   	{	
					parent.hiAlert("数据保存成功!", '系统提示');
					
					$("#empName").attr("value","");
					$("#empPwd").attr("value","");
					$("#imNumber").attr("value","");
					
					$("#empName").focus();
					return false;
			   	}
			   	else if (msg=='2')
			   	{
					parent.hiAlert("该客服账号已经存在!", '系统提示');
					$("#empName").focus();
					return false;
			   	}
			   	else if (msg=='3')
			   	{
					parent.hiAlert("客服人员数量已达到最大值，不允许继续增加!", '系统提示');
					$("#empName").focus();
					return false;
			   	}
			})
	        
		}

   		function CheckDataEdit(EID)
   		{
			value = $("#empName").attr("value");
	       	if( value=="")
	       	{
				parent.hiAlert("请输入客服账号!", '系统提示');
				$("#empName").focus();
				return false;
	        }

			var temp=document.getElementsByName("imtype");
			var imtypeValue="";
			for (i=0;i<temp.length;i++)
			{
			    if(temp[i].checked)
				{
					imtypeValue=temp[i].value;
				}
			}

			var strSQL = "";                      
			strSQL+= "&EID="+EID;
			strSQL+= "&empName=";
			strSQL+=$("#empName").attr("value");
			strSQL+= "&empPwd=";
			strSQL+=$("#empPwd").attr("value");
			strSQL+= "&imNumber=";
			strSQL+=$("#imNumber").attr("value");
			strSQL+= "&imType="+imtypeValue;
			strSQL+= "&Type=EditEmpName";
			
//			alert (strSQL);
			
			$.post("varifyData.php",strSQL,function(msg)
			{

//			    alert (msg);
			    
			   	if (msg=='1')
			   	{	
					parent.hiAlert("数据保存成功!", '系统提示');
					
					$("#empName").attr("value","");
					$("#empPwd").attr("value","");
					$("#imNumber").attr("value","");
					
					$("#empName").focus();
					return false;
			   	}
			   	else if (msg=='2')
			   	{
					parent.hiAlert("该客服账号已经存在!", '系统提示');
					$("#empName").focus();
					return false;
			   	}
			})
	        
	    }    
	</script>
</head>


<body>
	<div id="MenuRighttitle" ><div style="padding-left:245px;padding-top:5px;"><b><?=$Title;?></b></div></div>

	<div class="inner-container">
		<div class="bodypart" style="border:0px solid blue;">	
			<div style="padding-left: 120px; margin-top: 20px; text-align: left; min-height: 300px;border:0px solid blue;">

				<div class="userpwd-a04" style="margin-top:20px;"><b><?="客服账号:";?></b></div>
				<div class="userpwd-a05" style="margin-top:20px;"><input type="text" id="empName" name="empName" value="<?=$result["empName"];?>" size="30" maxlength="50" class="userinfo_textbox" /></div>

				<div class="userpwd-a04" style="margin-top:20px;"><b><?="客服密码:";?></b></div>
				<div class="userpwd-a05" style="margin-top:20px;"><input type="text" id="empPwd" name="empPwd" value="<?=$result["empPwd"];?>" size="30" maxlength="20" class="userinfo_textbox" /></div>

				<div class="userpwd-a04" style="margin-top:20px;"><b><?="即时通讯类型:";?>:</b></div>
				<div class="userpwd-a05" style="margin-top:20px;padding-top:5px;">
					<div class="empinfo_a13" style="margin-left:10px;"><input type="radio" name="imtype" id="imtype0" value="0" <?=$imtype=='0' ?'checked':''; ?>>旺旺</div>
					<div class="empinfo_a13" style="margin-left: 0px;"><input type="radio" name="imtype" id="imtype1" value="1" <?=$imtype=='1' ?'checked':''; ?>>QQ</div>
				</div>

				<div class="userpwd-a04" style="margin-top:20px;"><b><?="即时通讯号码:";?></b></div>
				<div class="userpwd-a05" style="margin-top:20px;"><input type="text" id="imNumber" name="imNumber" value="<?=$result["imNumber"];?>" size="30" maxlength="10" class="userinfo_textbox" /></div>
				
				<div class="userpwd-a01" style="margin-top: 20px;width:500px;text-align:center;border:0px solid blue;">
					<?
					if ($Type==0)
					{
					?>
						<input type="image" name="image" value="image" src="images/submit_btn.gif" onmouseout="this.src='images/submit_btn.gif'" onmouseover="this.src='images/submit_btn-hover.gif'" onclick="javascript:CheckData();" /> 
					<?
					}
					else if ($Type==1)
					{
					?>
						<input type="image" name="image" value="image" src="images/submit_btn.gif" onmouseout="this.src='images/submit_btn.gif'" onmouseover="this.src='images/submit_btn-hover.gif'" onclick="javascript:CheckDataEdit('<?=$result["id"];?>');" />
					<?
					}
					?>


					<input type="image" name="image" value="image" src="images/go_btn.gif" onmouseout="this.src='images/go_btn.gif'" onmouseover="this.src='images/go_btn-hover.gif'" onclick="javascript:goback('<?=$pgno;?>');" /> 
				</div>
			</div>
		</div>
	</div>
</body>

</html>
